<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title>调查问卷</title>
    <meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0" />
    <link rel="stylesheet" href="./css/index.css"/>
    <script src="./js/jquery.js"></script>
    <script src="lib/layer/layer.js"></script>
    <script src="js/base.js"></script>
    <script src="lib/vue/vue.min.js"></script>
    <script src="lib/vue/vue-resource.min.js"></script>
</head>
<script type="text/javascript">
    (function () {
        var deviceWidth = document.documentElement.clientWidth;
        if (deviceWidth > 640) deviceWidth = 640;
        document.documentElement.style.fontSize = deviceWidth / 6.4 + 'px';
    }());
</script>
<body>
<div class="infor"><img src="./images/survey.png" alt=""/></div>
<div class="perCenter" id="app">
    <p class="crumbs"><span class="bottom_color">首页</span> > <span>调查问卷</span></p>
    <h3 class="suvery">{{lists.name}}</h3>
    <ul class="suveryQ">
        <li v-for="(li,index) in lists">
            <div > <span><span v-if="index < 9">0</span>{{index+1}}</span> {{li.question}}</div>
            <span v-for="kk in li.keys" v-if="li.type == 1">
                <input  :id="'ques' + kk.id" type="radio" v-model="askAry[index].key" :value="kk.id"/>
                <label v-text="kk.desc" :for="'ques'+kk.id"></label>
            </span>
            <span v-for="kk in li.keys" v-if="li.type == 2">
                <input  :id="'ques' + kk.id" type="checkbox" v-model="askAry[index].key" :value="kk.id"/>
                <label v-text="kk.desc" :for="'ques'+kk.id"></label>
            </span>
             <span v-if="li.type == 3" >
                 <textarea v-model="askAry[index].key" ></textarea>
            </span>
        </li>
        <div class="suverySubmit"><button @click="submitS()">提交</button></div>
    </ul>
</div>
<div class="footer"></div>
</body>
<script>
    (function () {
        var app = new Vue({
            el: '#app',
            data: function () {
                return{
                    aurl: [],
                    lists:[],
                    askAry:[],
                    cont:'',
                    selg:{
                        slug:'questionnaire',
                        ask:[]
                    }


                }
            },
            mounted: function () {
                this.showData();
//需要执行的方法可以在mounted中进行触发，其获取的数据可以赋到data中后，可以放在前面进行渲染
            },
            methods: {
                showData: function () {
                    var _this = this;
                    get(url + 'crm/exam-paper?slug=questionnaire', {}).then(
                            function (res) {
                                if (res.body.code == 101) {
                                    tip(res.body.msg);
                                    location.href = './login.html'
                                } else if (res.body.code == 400) {
                                    tip(res.body.msg);
                                } else {
                                    _this.lists = _lists = res.data.data.asks;
                                    for(let i in _lists){
                                        let _tmpAry = {
                                            "id":_lists[i].id,
                                            "key":_lists[i].type==2?[]:''
                                        };
                                        _this.askAry.push(_tmpAry);
                                    }
                                }
                            }, function (reason) {
                                tip('请求错误')
                            });
                },
                submitS:function(){
                    var _this = this;
                        post(url + 'crm/exam-paper',{
                            'slug':'questionnaire',
                            'ask':_this.askAry
                        }).then(
                                function (res) {
                                    if (res.body.code == 101) {
                                        tip(res.body.msg);
                                        location.href = './login.html'
                                    } else if (res.body.code == 400) {
                                        tip(res.body.msg);
                                    } else {
                                        tip(res.body.msg);
                                    }
                                }, function (reason) {
                                    tip('请求错误')
                                });
                }
            }
        })
    })()
    $('.footer').load("./footer.html")
 </script>
</html>